fid = fopen('4-rand-rot-squares.txt', 'w');

l = sqrt(2)/2;
base_square = [l, l, -l, -l; l, -l, -l, l];
idx = 1;
for xbnd = -10:10:0
    for ybnd = -10:10:0
        fprintf(fid, 'PIECE %d\r\nQUANTITY\r\n1\r\nNUMBER OF VERTICES\r\n4\r\nVERTICES (X,Y)\r\n', idx);
        xt = rand(1, 1)*10 + xbnd;
        yt = rand(1, 1)*10 + ybnd;
        tsquare = base_square + [ones(1, 4)*xt; ones(1, 4)*yt];
        c = [xt; yt];
        angle = rand(1, 1)*3.14 + 3.14;
        mat = [cos(angle), -sin(angle); sin(angle), cos(angle)];
        for i = 1:4
            tsquare(:,i) = mat*(tsquare(:,i)-c) + c; 
            s = sprintf('%.6f %.6f\r\n', tsquare(1,i), tsquare(2, i));
            fprintf(fid, s);
        end
        fprintf(fid, '\r\n');        
        idx = idx + 1;
    end
end